{template header}
<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>

<script type="text/javascript">
    function uploadImage() {
        if($("#imgFile").val() != '') $("#upload_form").submit();
    }
    function upload_frame_load() {
        var data = $(window.frames['upload_frame'].document.body).html();
        if(data) {
            data = eval('(' + data + ')');
//            console.log(data);return false;
            if(data.status=='ok'){
                window.location.reload();
            }else{
                alert(data.error_msg);
            }
        }
    }
</script>
<div id="fream">
    <form id="upload_form" method="post" action="?c=adminErp&a=ajaxUploadImage&pid={$list['id']}" target="upload_frame" enctype="multipart/form-data">
        <input type="file" name="imgFile" id="imgFile" style="display:none;" onchange="uploadImage();">
    </form>
    <iframe id="upload_frame" name="upload_frame" style="display:none" onLoad="upload_frame_load();"></iframe>
</div>


<!--<form class="form-horizontal"  action="?c=adminErp&a=addErpProduct">-->
   <input type="hidden" id='pid' name="pid" value="{$list['id']}">
    <!--规格开始-->
    <h4 style="padding-left:10px;;">
        <a href="?c=adminErp&a=getErpProductList"><span>库存列表</span></a>
        >>
        <a href="?c=adminErp&a=getProductDetail&pid={$list['id']}"><span>货品详情</span></a> <!--<span class="btn btn-primary" id="addGg" >添加规格</span>-->
    </h4>


<table style="width: 100%" border="1">
    <thead>
    <tr>
        <td>货号</td>
        <td>名称</td>
        <td>类别</td>
        <td>运费</td>
        <td>入库数量</td>
        <td>现存数量</td>
    </tr>
    <tr>
        <td>{$list['code']}</td>
        <td>{$list['title']}</td>
        <td>{$list['categoryName']}</td>
        <td>{$list['express_fee']} <a href="#dialogProductExpress" data-toggle="modal">修改</a></td>
        <td>{$list['stock_into_num']}</td>
        <td>{$list['real_stock_num']}</td>
    </tr>
    </thead>
</table>

<div id="dialogProductExpress" class="modal hide fade">
    <div class="modal-body">
        <span>运费：</span><input type="text"  id="productExpress" value="{$list['express_fee']}" /><br />
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" data-pid="{$list['id']}" id="submitProductExpress" >确定</button>
        <button class="btn" data-dismiss="modal" >取消</button>
    </div>
</div>
<script>
    $('#submitProductExpress').click(function(){
        var express = $('#productExpress').val()
        if (!express) {
            alert('请填写内容');return false;
        }
        var pid = $(this).data('pid')
        $.post('?c=adminErp&a=updateErpProductExpress',{id:pid,express:express},function(d){
            d = JSON.parse(d)
            if(d.status=='ok'){
                alert(d.error_msg);
                window.location.reload();
            }else{
                alert(d.error_msg);
            }
        })
    })
</script>

<h4 style="padding-left:10px;;">
    <span>图片</span>
</h4>

<div class="control-group">
    <label class="control-label" >规格图片：</label>
    <div class="controls">
        <button type="button" id="file_upload_btn" class="btn btn-primary" onclick="$('#imgFile').trigger('click')">
            <i class="ace-icon fa fa-cloud-upload bigger-110"></i>上传图片
        </button>
    </div>
</div>

<div class="control-group">
    <div class="controls" id="showImage">
        {if count($list['imageList'])>0}
            {loop $list['imageList'] $k $v}
                <span style="margin: 10px  10px 10px 10px">
                    <img src="{$v['image_url']}" style="width: 100px;height: 100px;">
                    <span class="btn btn-primary" id="delImg_{$v['id']}" ids="{$v['id']}">删除</span>
                </span>
            {/loop}
        {/if}
    </div>
</div>

<h4 style="padding-left:10px;;">
    <span>货品明细</span>
</h4>

<table style="width: 100%" border="1">
    <thead>
    <tr>
        <td>规格</td>
        <td>入库总数</td>
        <td>现存数量</td>
    </tr>
    {if count($list['childGoods'])>0}
        {loop $list['childGoods'] $k $v}
            <tr>
                <td>{$v['attrPathName']}</td>
                <td>{$v['stockIntoNum']}</td>
                <td>{$v['realStockNum']}</td>
            </tr>
        {/loop}
    {/if}
    </thead>
</table>

<h4 style="padding-left:10px;;">
    <span>入库明细</span>
</h4>

<table style="width: 100%" border="1">
    <thead>
    <tr>
        <td>时间</td>
        <td>操作人</td>
        <td>规格</td>
        <td>入库总数</td>
        <td>货品成本</td>
        <td>总价</td>
    </tr>
    {if count($list['arrStockIntoList'])>0}
        {loop $list['arrStockIntoList'] $k $v}
            <tr>
                <td>{$v['formatTime']}</td>
                <td>{$v['operateName']}</td>
                <td>{$v['attrPathName']}</td>
                <td>{$v['stockIntoNum']}</td>
                <td>{$v['price']}</td>
                <td>{eval echo bcmul($v['stockIntoNum'],$v['price'],2)}</td>
            </tr>
        {/loop}
    {/if}
    </thead>
</table>

<h4 style="padding-left:10px;;">
    <span>盘点明细</span>
</h4>

<table style="width: 100%" border="1">
    <thead>
    <tr>
        <td>时间</td>
        <td>盘点人</td>
        <td>规格</td>
        <td>理论库存</td>
        <td>实际库存</td>
        <td>原因</td>
    </tr>
    {if count($list['arrStockCheckList'])>0}
        {loop $list['arrStockCheckList'] $k $v}
            <tr>
                <td>{$v['formatTime']}</td>
                <td>{$v['operateName']}</td>
                <td>{$v['attrPathName']}</td>
                <td>{$v['currentStockNum']}</td>
                <td>{$v['realStockNum']}</td>
                <td>{$v['content']}</td>
            </tr>
        {/loop}
    {/if}
    </thead>
</table>

{template footer}
<div class="bg" id="bgx"></div>
<div id="dialog" style="position: absolute; z-index: 1003;background-color:white; display: none;" >
    <div  style="margin:50px 100px;">
        <div class="controls">
            <div style="padding-left:20px;">确定操作？</div><br />
            <div style="text-align: center">
                <button class="btn btn-primary" id="ok" ids="">确定</button>
                <button class="btn btn-primary" id="close" >取消</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("span[id^='delImg_']").on('click',function(){//删除图片
        var _this =$(this),_ids = _this.attr('ids');
        $("#bgx").show();
        $('#ok').attr({ids:_ids});
        letDivCenter('#dialog');
    })

    $('#ok').on('click',function(){
        var _this = $(this),_ids = _this.attr('ids');
            $.ajax({
                type:'POST',
                url:'?c=adminErp&a=delProductImage',
                data:{imagesId:_ids},
                dataType:'json',
                success:function(d){
                    if(d.status=='ok'){
                        alert(d.error_msg);
                        window.location.reload();
                    }else{
                        alert(d.error_msg);
                    }
                }
            })
        $('#close').click();
    })
    $('#close').on('click',function(){
        $('#dialog').css('display','none');
        $("#bgx").fadeOut(300);
    })
    function letDivCenter(divName){
        var divObj = $(divName);
        var wWidth = $(document.body).width(),wHeight = $(window).height();
        var divWidth = divObj.width(),divHeight = divObj.height();
        divObj.css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop(),'display':'block'});
        $(window).bind('scroll resize',function(){
            $(divName).css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop()});
        });
    }

    function unique(arrRemark) {
            var n = {},r=[]; //n为hash表，r为临时数组
            for(var i = 0; i < arrRemark.length; i++) //遍历当前数组
            {
                if (!n[this[i]]) //如果hash表中没有当前项
                {
                    n[this[i]] = true; //存入hash表
                    r.push(this[i]); //把当前数组的当前项push到临时数组里面
                }
            }
            return r;
    }
</script>